package com.Repository;


import com.entity.Student;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;

@Repository
public interface StudentRepository extends JpaRepository<Student, Long>, JpaSpecificationExecutor<Student> {

//查2. 自定义函数接口： Or And In Like Between等
    //public Student getById(Long id);
    public List<Student> getById(Long id);
    public List<Student> getByAge(int age);
    public List<Student> getByName(String name);

    public Student getByNameAndScore(String name, Double score);
    public List<Student> getByNameOrScore(String name, Double score);
    public List<Student> findByNameLike(String name);

    public List<Student> findByScoreLessThan(Double max);
    public List<Student> findByAgeBetween(int min, int max);




//查3. jpal查询I
    //占位从1开始：？1
    @Query("from Student  where  name = ?1 or age = ?2")
    List<Student> findByCondition2(String name, Integer age);

    @Query("from Student  where  name = :name or age = :age")
    List<Student> findByCondition3(@Param("name") String untitled1, @Param("age") Integer untitled2);
    //:name 和 @Param("name") 名字必须一样，和String untitled1可以不一样

    //传入对象Bean，那么jpql的写法为：固定写法，没有为什么
    @Query("from Student s where  s.name = :#{#student.name} or s.age = :#{#student.age}")
    List<Student> findByCondition4(@Param("student") Student student);



//查4. mysql查询
    @Query(value = "select * from student s where  s.name = ?1 or s.age = ?2", nativeQuery = true)
    List<Student> findByMysql(String name, Integer age);
}
/*
问1：
* 接口继承父类，那么有什么作用？
* 特点：首先，接口肯定是无法实现的，那么就只能由父类实现。
* 作用：自己封装第三方提供的接口
* 实现：没有试出来
* */